var url = '';

function isOrderStatus(index,check) {
  if(check===""||check==null){
    check=true;
  }
  if(check){
    switch (index) {
      case '0':
        return '<span style="color: #1990FF;">进行中</span>';
      case '1':
        return '<span style="color: #FFB800;text-decoration:underline;">待审核</span>';
      case '2':
        return '<span style="color: #389E0D;">已完成</span>';
    }
  }else {
    return '<span style="color: #e01010;">待投料</span>';
  }
}

function isParentOrderStatus(index) {
  switch (index) {
    case false:
      return '<span style="color: #1990FF;">进行中</span>';
    case true:
      return '<span style="color: #389E0D;">已完成</span>';
  }
}

function isReportStatus(index) {
  switch (index) {
    case false:
      return '<span style="color: #ff1919;cursor: pointer;" onclick="tipsUser()">未完工</span>';
    case true:
      return '<span style="color: #389E0D;cursor: pointer;">已完工</span>';
  }
}

function isCheckStatus(index) {
  switch (index) {
    case false:
      return '<span style="color: #ff1919;cursor: pointer;">未通过</span>';
    case true:
      return '<span style="color: #389E0D;cursor: pointer;">已通过</span>';
  }
}

function tipsUser() {
  layer.msg("未完工的工单，可以回到< 工单管理 >-< 我的待办 >继续上报!");
}

  function isMachineStatus(index) {
    switch (index) {
      case false:
        return '<span style="color: #ff1919;">不可用</span>';
      case true:
        return '<span style="color: #389E0D;">可用</span>';
    }
  }

function adminLevel(index) {
  switch (index) {
    case '0':
      return '二级管理员';
    case '1':
      return '超级管理员';
    case '2':
      return '普通操作员';
  }
}

function getProcess(str) {
  var result;
  $.ajax({
    url: url + '/process-info/getProcessName',
    method: 'POST',
    async : false,
    contentType: 'application/json',
    data: JSON.stringify({
      ids:str
    }),
    success: function(res) {
      result=res.data;
    }
  })
  return result;
}

function isNotEmptyObject(data) {
  JSON.stringify(data)
  for (var i in data) {
    if($.isEmptyObject(data[i])){
      return false;
    }
  }
  return true;
}

function isAdminOfOrder() {
  $.ajax({
    url: '/sys-user/getAdmin/'+sessionStorage.getItem('userId'),
    method: 'GET',
    contentType: 'application/json',
    success: function (res) {
      if (res.code===200){
      }
      else if (res.code===400){
        $('#deptName').attr('disabled','disabled');
        $('#orderDept').attr('disabled','disabled');
        layer.msg("非管理员只能查看本部门工单");
      }
    }
  })
}

function childStatus(index,status) {
  switch (status) {
    case '0':
      return '  <h2 class="layui-colla-title" style="color:#01AAED">'+index+'</h2>';
    case '1':
      return '  <h2 class="layui-colla-title" style="color:#FFB800">'+index+'</h2>';
    case '2':
      return '  <h2 class="layui-colla-title" style="color:#46c16c">'+index+'</h2>';
  }
}

function userStatus(index) {
  switch (index) {
    case true:
      return '<span style="color: #389E0D;cursor: pointer;">使用中</span>';
    case false:
      return '<span style="color: #ff1919;cursor: pointer;">禁用中</span>';
  }
}
function productStatus(index) {
  switch (index) {
    case true:
      return '<span style="color: #389E0D;cursor: pointer;">在产</span>';
    case false:
      return '<span style="color: #ff1919;cursor: pointer;">停产</span>';
  }
}

function checkAmount(total,now,reportedGood,reportedBad,good,bad,status) {
  if(now!==0){
    if(now===good+bad+reportedGood+reportedBad&&status===0){//达到但选择未完结
      return "300";
    }
    if(now>good+bad+reportedGood+reportedBad&&status===1){//未达到但选择完结
      return "400";
    }
  }else{
    if(total===good+bad+reportedGood+reportedBad&&status===0){//达到但选择未完结
      return "300";
    }
    if(total>good+bad+reportedGood+reportedBad&&status===1){//未达到但选择完结
      return "400";
    }
  }
  return "200"
}

function processStatus(index) {
  switch (index) {
    case true:
      return '<span style="color: #389E0D;cursor: pointer;">是</span>';
    case false:
      return '<span style="color: #ffa900;cursor: pointer;">否</span>';
  }
}


function checkStatus(index) {
  switch (index) {
    case true:
      return "<button  type='button' style='background-color:#389E0D ' class='layui-btn layui-btn-sm'>已完成检录</button>"
    case false:
      return "<button  type='button' class='layui-btn layui-btn-sm layui-bg-red'>首站投料检录</button>"
  }
}

function coreStatus(index) {
  switch (index) {
    case true:
      return '<span style="color: #389E0D;cursor: pointer;">在用</span>';
    case false:
      return '<span style="color: #ff1919;cursor: pointer;">停用</span>';
  }
}

function coreButton(index) {
  switch (index) {
    case true:
      return "<button class='layui-btn layui-bg-green layui-btn-sm'>一键停用此CORE</button>";
    case false:
      return "<button class='layui-btn layui-btn-danger layui-btn-sm'>一键启用此CORE</button>";
  }
}

function mouldStatus(index) {
  switch (index) {
    case "0":
      return "<button class='layui-btn layui-bg-green layui-btn-sm'>待上传文件</button>";
    case "1":
      return '<span style="color: #389E0D;cursor: pointer;">在用</span>';
    case "2":
      return '<span style="color: #ff1919;cursor: pointer;">停用</span>';
  }
}

function mouldButton(index) {
  switch (index) {
    case true:
      return "<button class='layui-btn layui-bg-green layui-btn-sm'>停用</button>";
    case false:
      return "<button class='layui-btn layui-btn-danger layui-btn-sm'>启用</button>";
  }
}


function checkMould(index,id) {
  var msg="该产品未绑定模板文件或模板信息被停用，无法导出，请联系管理员"
  switch (index) {
    case true:
      return "<input name='downSelect' type='checkbox' alt='" +id+ "'>";
    case false:
      return "<input name='downSelect' disabled='disabled' type='checkbox' alt='" +id+ "'>";
  }
}

function isCheckInit(index,id) {
  switch (index) {
    case true:
      return "<input name='checkSelect' disabled='disabled' type='checkbox' alt='" +id+ "'>";
    case false:
      return "<input name='checkSelect' type='checkbox' alt='" +id+ "'>";
  }
}

function isAllow(index,id) {
  switch (index) {
    case true:
      return "<input name='downFromERPSelect' disabled='disabled' type='checkbox' alt='" +id+ "'>";
    case false:
      return "<input name='downFromERPSelect' type='checkbox' alt='" +id+ "'>";
  }
}

//获取时间
function getRecentDay(day){
  debugger
  var today = new Date();
  var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
  today.setTime(targetday_milliseconds);
  var tYear = today.getFullYear();
  var tMonth = today.getMonth();
  var tDate = today.getDate();
  tMonth = doHandleMonth(tMonth + 1);
  tDate = doHandleMonth(tDate);
  return tYear+"-"+tMonth+"-"+tDate;
}

function doHandleMonth(month){
  var m = month;
  if(month.toString().length == 1){
    m = "0" + month;
  }
  return m;
}

//ca值
function caLevel(index) {
  index=index.replace('%','');
  var ca=Number(index);
  if(ca<=12.5){
    return '<div style="border-radius: 30px;background-color: #0df600"><b style="color:white;">A</b></div>';
  }
  if(12.5<ca&&ca<=25.0){
    return '<div style="border-radius: 30px;background-color: greenyellow"><b style="color:white;">B</b></div>';
  }
  if(25.0<ca&&ca<=50.0){
    return '<div style="border-radius: 30px;background-color: #FFB800"><b style="color:white;">C</b></div>';
  }
  if(ca>50.0){
    return '<div style="border-radius: 30px;background-color: #FF5722"><b style="color:white;">D</b></div>';
  }
}
//cp值
function cpLevel(index) {
  var cp=Number(index);
  if(cp>=1.67){
    return '<div style="border-radius: 30px;background-color: #0df600"><b style="color:white;">A+</b></div>';
  }
  if(1.33<=cp&&cp<1.67){
    return '<div style="border-radius: 30px;background-color: greenyellow"><b style="color:white;">A</b></div>';
  }
  if(1.0<=cp&&cp<1.33){
    return '<div style="border-radius: 30px;background-color: #FFB800"><b style="color:white;">B</b></div>';
  }
  if(0.67<=cp&&cp<1.0){
    return '<div style="border-radius: 30px;background-color: #FF5722"><b style="color:white;">C</b></div>';
  }
  if(cp<0.67){
    return '<div style="border-radius: 30px;background-color: #ff0000"><b style="color:white;">D</b></div>';
  }
  return '<div style="border-radius: 30px;background-color: #000000"><b style="color:white;">?</b></div>';
}
//cpk值
function cpkLevel(index) {
  var cpk=Number(index);
  if(cpk>=1.67){
    return '<div style="border-radius: 30px;background-color: #0df600"><b style="color:white;">A+</b></div>';
  }
  if(1.33<=cpk&&cpk<1.67){
    return '<div style="border-radius: 30px;background-color: greenyellow"><b style="color:white;">A</b></div>';
  }
  if(1.0<=cpk&&cpk<1.33){
    return '<div style="border-radius: 30px;background-color: #FFB800"><b style="color:white;">B</b></div>';
  }
  if(0.67<=cpk&&cpk<1.0){
    return '<div style="border-radius: 30px;background-color: #FF5722"><b style="color:white;">C</b></div>';
  }
  if(cpk<0.67){
    return '<div style="border-radius: 30px;background-color: #ff0000"><b style="color:white;">D</b></div>';
  }
  return '<div style="border-radius: 30px;background-color: #000000"><b style="color:white;">?</b></div>';
}




